package com.wang.head.intercepor;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import com.wang.common.controller.BaseController;
import com.wang.common.util.ConstatFinalUtil;
import com.wang.users.pojo.AUsers;
import com.wang.users.service.IUsersDbService;

/**
 * 配置拦截器
 * @author Xh-Win10-Server
 */
@Component("authHeadInterceptor")
public class AuthHeadInterceptor extends BaseController implements HandlerInterceptor
{
	@Resource
	private IUsersDbService usersDbService;
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
	{
		ConstatFinalUtil.SYS_LOGGER.info("--preHandle--");
		
		/* 设置一些公共的变量 */
		this.commonOper(request);
		
		HttpSession session = request.getSession();
		AUsers users = (AUsers) session.getAttribute("usersSess");
		
		if(users != null)
		{
			return true ; 
		}
		
		String loginUrl = request.getContextPath() + "/login" ; 
		response.sendRedirect(loginUrl);
		return false;
	}
}
